package com.gtxd.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.gtxd.dao.impl.PatientinfoDao;
import com.gtxd.entity.Patientinfo;
import com.gtxd.service.CommonService;
import com.gtxd.service.IPatientinfoService;
import com.gtxd.utils.PageParams;
import com.gtxd.utils.PageUtils;
import com.gtxd.utils.R;

@Service("patientinfoService")
public class PatientinfoService implements IPatientinfoService {
	@Autowired
	CommonService commonService;

	@Autowired
	PatientinfoDao patientinfoDao;

	@Override
	public boolean deletebatch(Object object, String[] ids, String key) throws Exception {
		return patientinfoDao.deletebatch(new Patientinfo(), ids, key);

	}

	/**
	 * 
	 * yangc 2018年1月17日 下午5:10:49
	 * <p>
	 * Title: listBy
	 * </p>
	 * <p>
	 * Description: 条件筛选查询列表
	 * </p>
	 * 
	 * @param params
	 * @return
	 * @throws Exception
	 */
	@Override
	@Transactional
	public R screening(Map<String, Object> params) throws Exception {
		// 查询列表数据
		PageParams query = new PageParams(params);

		StringBuffer hql = new StringBuffer();
		/*
		 * FROM
		 */
		hql.append("FROM Patientinfo ");
		/*
		 * WHERE
		 */
		hql.append("WHERE 1=1 ");
		// merchantPid=1&

		if (params.get("dname") != null && !"".equals(params.get("dname")))
			hql.append("and dname like '%" + params.get("dname") + "%' ");
		/*
		 * ORDER BY
		 */
		if (query.getSidx() != null && !query.getSidx().equals(""))
			hql.append(" ORDER BY " + query.getSidx() + " " + (query.getOrder() ? "ASE" : "DESC"));
		List<?> number = commonService.queryByHql(hql.toString());
		int total = number == null ? 0 : number.size();

		List<?> list = null;
		PageUtils pageUtil = new PageUtils(list, total, query.getPageSize(), query.getCurrentPage());
		if (total > 0) {
			list = commonService.queryByHql(hql.toString(), query);
			pageUtil = new PageUtils(list, total, query.getPageSize(), query.getCurrentPage());

		}

		return R.ok().put("page", pageUtil);

	}
}
